<%@ include file="connect.jsp" %>
<%--
  Created by IntelliJ IDEA.
  User: Mery
  Date: 10/25/12
  Time: 11:03 PM
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    if (session.getAttribute("namaUser") == null) {

        response.sendRedirect("login.jsp?respon=You have to login first!");
    }

%>


<html>
<head>
    <title>Business English</title>
    <script type="text/javascript" src="jquery.min.js"></script>
    <script type="text/javascript" src="jquery.leanModal.min.js"></script>
    <script type="text/javascript">
        $(function () {
            $("#newmaterial").leanModal({ top:200, closeButton:".modal_close" });
        });
    </script>
    <link href="style.css" rel="stylesheet"/>
    <script type="text/javascript" language="javascript">
        function confirmAction() {
            var confirmed = confirm("Are you sure want to delete this material?");
            return confirmed;
        }
    </script>
    <script src="jquery.js" type="text/javascript"></script>
    <script src="facebox.js" type="text/javascript"></script>
    <script type="text/javascript">
        jQuery(document).ready(function ($) {
            $('a[rel*=facebox]').facebox({
                loadingImage:'images/loading.gif',
                closeImage:'images/closelabel.png'
            })
        })
    </script>
</head>

<body>
<table id="bg" cellspacing="0">
    <tr id="header">

        <td class="link">
            <%@ include file="header.jsp" %>
        </td>
    </tr>
    <tr id="menu">
        <td>
            <%@ include file="menu.jsp" %>
        </td>
    </tr>
    <tr id="hr">
        <td><hr width="100%" size="8" noshade="noshade" ></td>
    </tr>
    <tr id="content">
        <td class="link" valign="top" style="padding-left: 20px">
            <table>

                <tr id="title">
                    <td>Learn</td>

                </tr>

                <tr>
                    <td>
                        <div class="btn-fld">
                            <a id="newmaterial" rel="facebox" name="signup" href="#popup">
                                <button type="button">Add New Material</button>
                            </a></div>
                    </td>
                </tr>
                <table>
                    <tr id="warning">
                        <td>

                            <%
                                String respon = request.getParameter("respon");

                                if (respon != null) {

                                    out.print(respon + " ");
                                } %>
                        </td>
                    </tr>
                </table>
                <table width="500px" id="bor1" border="2">
                    <tr align="center" style="font-weight: 600">
                        <td  width="12px">No</td>
                        <td>Learn's Name</td>
                        <td>Category</td>
                        <td>Action</td>
                    </tr>
                    <tr>
                        <%
                            int i = 0;
                            ResultSet rs = stat.executeQuery("select * from learn a, categories b where a.categoryID = b.categoryID group by CategoryId,LearnName");
                            while (rs.next()) {
                                i = i + 1;
                                String id = rs.getString("learnID");
                        %>
                        <td align="center"><%=i%>
                        </td>
                        <td><%out.print(rs.getString("learnName"));%></td>
                        <td><%out.print(rs.getString("categoryName"));%></td>
                        <td align="center"><a href="EditLearn.jsp?id=<%=id%>">
                            <img height="25px" src="search_folder.png" title="Show Word"></a>
                            <a href="doDeleteLearn.jsp?id=<%=id%>&name=<%=rs.getString("learnName")%>"
                               onclick="return confirmAction()"><img height="25px" src="Delete.png"
                                                                     title="Delete Material"></a></td>
                    </tr>
                    <% } %>

                </table>


            </table>
        </td>
    </tr>

    <div id="popup">
        <div id="signup-ct">
            <div id="popup-header">
                <h2>Add New Material</h2>

            </div>

            <form action="AddNewMaterial.jsp">

                <div class="txt-fld">
                    <label style="margin-top: 10px; margin-left: 10px">Choose Category :</label>
                    <select style="margin-top: 10px; width: 155px; font-family: Segoe UI; font-size: 12pt "
                            name="category">

                        <%

                            String idkat = request.getParameter("category");

                            rs = stat.executeQuery("select * from categories order by categoryid asc");
                            while (rs.next()) {
                                String kategori = rs.getString("categoryName");
                                String idKategori = rs.getString("categoryID");
                        %>

                        <option value="<%=kategori%>"><%=kategori%>
                        </option>
                        <%}%>
                    </select>

                </div>

                <div class="btn-fld">
                    <button type="submit">Add</button>
                </div>
            </form>
        </div>
    </div>

</table>
</body>
</html>